from dataclasses import dataclass
from typing import List, Optional, Any

from dataclasses_json import dataclass_json


@dataclass_json
@dataclass
class User:
    id: str = None
    user_name: str = None
    auth_type: str = None
    user_type: int = None


@dataclass
class AccountSummary:
    id: str
    name: str
    exchange: str
    equity: float
    expire: float
    open: float
    mm: float


@dataclass
class AccountGroupSummary:
    id: str
    name: float
    total_equity: float
    summaries: List[AccountSummary]


@dataclass
class Position:
    instrument: str
    size: float
    avg_price: float


@dataclass
class CurrencyPosition:
    currency: str
    spot: float
    delta: float
    positions: List[Position]


@dataclass
class OpenOrder:
    currency: str
    instrument: str
    order_id: str
    price: float = 0
    amount: float = 0
    filled_amount: float = 0


@dataclass
class AccountPosition:
    id: str
    name: str
    exchange: str
    details: List[CurrencyPosition]


@dataclass
class FutureFundRateDetail:
    currency: str
    exchange: str
    instrument: str
    is_reverse: bool
    mark_price: float
    index_price: float


@dataclass
class DeliveryFundRateDetail(FutureFundRateDetail):
    expire_days: int
    found_rate: Optional[float] = None
    future_type: str = 'Delivery'


@dataclass
class PerpetualFundRateDetail(FutureFundRateDetail):
    interest_rate: float
    interest_8h: float = None
    interest_week: float = None
    future_type: str = 'Perpetual'
    expire_days: int = None


@dataclass
class FutureInstrumentInfo:
    exchange: str
    instrument: str
    is_reverse: bool
    future_type: str
    base_currency: str
    margin_currency: str
    min_tick_size: float = None
    step_tick_size: float = None
    min_trade_size: float = None
    step_trade_size: float = None
    expire_ts: Optional[int] = None


@dataclass
class Request:
    req_id: int
    method: str
    params: Optional[Any]


@dataclass
class Response:
    req_id: int
    method: str
    code: int
    data: Optional[Any]
